package com.unytech.wisdomcommunity.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.unytech.wisdomcommunity.R;
import com.unytech.wisdomcommunity.constant.StringConstants;
import com.viewpagerindicator.TabPageIndicator;

/**
 * 底部导航凸起按钮对应的界面  "有邻圈"的界面
 */
public class InteractActivity extends Activity {

    private TabPageIndicator mTabPageIndicator;
    private ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interact);

        initView();
    }
    private void initView() {
        mTabPageIndicator = ((TabPageIndicator)findViewById(R.id.interact_tpi));
        mViewPager = (ViewPager)findViewById(R.id.interact_vp);

        mViewPager.setAdapter(mPagerAdapter);
        mTabPageIndicator.setViewPager(mViewPager);

        mTabPageIndicator.setOnPageChangeListener(mPageListener);//tpi设置监听
    }
    //给TabPageIndicator设置监听器
    private ViewPager.OnPageChangeListener mPageListener= new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };

    //ViewPager的适配器
    private PagerAdapter mPagerAdapter = new PagerAdapter() {
        @Override
        public int getCount() {
            return StringConstants.INTERACT_TPI==null?0: StringConstants.INTERACT_TPI.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return StringConstants.INTERACT_TPI[position];
        }
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            //return super.instantiateItem(container, position);
            TextView textView = new TextView(container.getContext());
            textView.setText(StringConstants.INTERACT_TPI[position]);
            textView.setGravity(Gravity.CENTER);
            container.addView(textView);

            return textView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            //super.destroyItem(container, position, object);
            container.removeView((View) object);
        }
    };
}